const {
  DataTypes
} = require('sequelize');
module.exports = sequelize => {
  const attributes = {
    id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      comment: null,
      primaryKey: true,
      field: "id",
      autoIncrement: true
    },
    name: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: null,
      comment: "角色名称",
      primaryKey: false,
      field: "name",
      autoIncrement: false,
      unique: "uk_name"
    },
    code: {
      type: DataTypes.CHAR,
      allowNull: false,
      defaultValue: null,
      comment: "角色编码",
      primaryKey: false,
      field: "code",
      autoIncrement: false
    },
    sort: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      comment: "显示顺序",
      primaryKey: false,
      field: "sort",
      autoIncrement: false
    },
    status: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      comment: "角色状态(1-正常 0-停用)",
      primaryKey: false,
      field: "status",
      autoIncrement: false
    },
    dataScope: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      comment: "数据权限(0-所有数据 1-部门及子部门数据 2-本部门数据3-本人数据)",
      primaryKey: false,
      field: "data_scope",
      autoIncrement: false
    },
    createBy: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: null,
      comment: "创建人 ID",
      primaryKey: false,
      field: "create_by",
      autoIncrement: false
    },
    createTime: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: null,
      comment: "创建时间",
      primaryKey: false,
      field: "create_time",
      autoIncrement: false
    },
    updateBy: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: null,
      comment: "更新人ID",
      primaryKey: false,
      field: "update_by",
      autoIncrement: false
    },
    updateTime: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: null,
      comment: "更新时间",
      primaryKey: false,
      field: "update_time",
      autoIncrement: false
    },
    isDeleted: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
      comment: "逻辑删除标识(0-未删除 1-已删除)",
      primaryKey: false,
      field: "is_deleted",
      autoIncrement: false
    }
  };
  const options = {
    tableName: "sys_role",
    comment: "",
    indexes: []
  };
  const SysRoleModel = sequelize.define("sys_role_model", attributes, options);

  // 添加关联关系
  SysRoleModel.associate = function(models) {
    SysRoleModel.hasMany(models.sys_user_role_model, {
      foreignKey: 'roleId'
    });
  };

  return SysRoleModel;
};